Column

Crescimento populacional (2022-2010)

Crescimento populacional (2022-2000)

Densidade populacional (2022)

População (2000)

População (2010)

População (2022)

Column

Tabela

Bairros População 2000 População 2010 População 2022 Densidade 2022 (hab/km²) Crescimento (2022-2010) Crescimento (2010-2000)
2 ÁGUA FRIA 3069 6269 6996 4.4031664 11.5967459 127.956989
3 AEROCLUBE 4057 9649 14226 6.8363127 47.4349674 250.653192
4 ALTIPLANO CABO BRANCO 4151 5233 10443 4.8170151 99.5604816 151.577933
5 ALTO DO CÉU 14187 16557 18727 7.4385422 13.1062391 32.001128
6 ALTO DO MATEUS 16898 16281 15348 6.1350738 -5.7306062 -9.172683
7 ANATÓLIA 1126 1162 1171 6.8199292 0.7745267 3.996448
8 ESTADOS 6479 7458 10230 5.5687182 37.1681416 57.894737
9 INDÚSTRIAS 7755 8712 12575 6.8269788 44.3411387 62.153449
10 IPÊS 10121 9121 8621 4.6166954 -5.4818551 -14.820670
11 BANCÁRIOS 10367 11863 16627 7.5774224 40.1584759 60.383910
12 BESSA 7111 13096 16414 7.7768117 25.3359805 130.825482
13 BRISAMAR 4148 4268 7247 12.2815391 69.7985005 74.710704
14 CABO BRANCO 5439 7906 8268 4.4538085 4.5788009 52.013238
15 CASTELO BRANCO 11208 11642 9900 2.7046081 -14.9630648 -11.670236
16 CENTRO 4998 3644 2710 1.4337927 -25.6311745 -45.778311
17 CIDADE DOS COLIBRIS 1802 4095 8103 7.4139972 97.8754579 349.667037
18 PADRE ZÉ 7053 6964 5988 12.9083485 -14.0149339 -15.099958
19 COSTA E SILVA 7716 8208 6935 6.9454375 -15.5092593 -10.121825
20 CRISTO REDENTOR 37170 37538 38073 7.7308298 1.4252224 2.429378
21 CRUZ DAS ARMAS 25994 25549 20491 8.2304881 -19.7972523 -21.170270
22 CUIÁ 3418 6944 13522 7.0201670 94.7292627 295.611469
23 DISTRITO INDUSTRIAL 3204 1887 3147 0.4482361 66.7726550 -1.779026
24 ERNANI SÁTIRO 8447 8641 10321 7.9412023 19.4421942 22.185391
25 ERNESTO GEISEL 12049 14184 13683 7.1407421 -3.5321489 13.561291
26 EXPEDICIONÁRIOS 3384 3625 3946 9.7047683 8.8551724 16.607565
27 FUNCIONÁRIOS 16222 15848 14606 8.4114916 -7.8369510 -9.961780
28 GROTÃO 5784 6159 4776 14.2454334 -22.4549440 -17.427386
29 ILHA DO BISPO 6020 7986 7045 1.4518187 -11.7831205 17.026578
30 JAGUARIBE 14368 14651 11968 5.0293265 -18.3127432 -16.703786
31 JOÃO PAULO II 9912 15446 19197 8.5938388 24.2846044 93.674334
32 JOÃO AGRIPINO 1206 1161 1745 8.1808992 50.3014643 44.693201
33 JOSÉ AMÉRICO 8776 16269 17535 6.8519190 7.7816707 99.806290
34 JARDIM CIDADE UNIVERSITÁRIA 11108 21425 25543 10.5237530 19.2205368 129.951386
35 JARDIM OCEANIA 10015 15283 20651 8.7163998 35.1239940 106.200699
36 JARDIM SÃO PAULO 2543 4550 4455 11.5474056 -2.0879121 75.186787
37 JARDIM VENEZA 12494 12812 13084 5.4665970 2.1230097 4.722267
38 MANAÍRA 19289 26369 26464 10.8968323 0.3602715 37.197366
39 MANDACARÚ 12776 12593 9884 9.5381851 -21.5119511 -22.636193
40 MANGABEIRA 67398 75988 68808 6.5773672 -9.4488603 2.092050
41 MIRAMAR 6986 9500 11483 8.6214452 20.8736842 64.371600
42 MUCUMAGO 4882 6276 12977 10.8512134 106.7718292 165.813191
43 OITIZEIRO 31028 29125 25818 8.2465106 -11.3545064 -16.791285
44 PARATIBE 8134 12396 20920 4.7892655 68.7641175 157.192033
45 PENHA 773 772 648 1.6061407 -16.0621762 -16.170763
46 PEDRO GONDIM 2739 3360 3634 4.6853861 8.1547619 32.676159
47 PLANALTO DA BOA ESPERANÇA 3318 6213 14318 6.9704683 130.4522775 331.525015
48 PONTA DO SEIXAS 383 474 542 0.8461914 14.3459916 41.514360
49 PORTAL DO SOL 1878 4136 11278 2.1054589 172.6789168 500.532481
50 ROGER 10215 10381 8192 4.9785476 -21.0866005 -19.804209
51 SÃO JOSÉ 7923 7078 6055 16.7918502 -14.4532354 -23.576928
52 TAMBAÚ 6782 10163 9899 10.3186406 -2.5976582 45.959894
53 TAMBIÁ 2172 2541 2127 2.6196666 -16.2927981 -2.071823
54 TAMBAUZINHO 4466 4932 5769 5.7466751 16.9708029 29.175996
55 TREZE DE MAIO 7850 7760 7968 10.1975068 2.6804124 1.503185
56 TORRE 17104 15193 13549 6.2818453 -10.8207727 -20.784612
57 TRINCHEIRAS 8765 6995 5581 6.1226424 -20.2144389 -36.326298
58 VARJÃO 19112 16973 14277 9.3791565 -15.8840511 -25.298242
59 VALENTINA 22306 22452 20890 6.6540362 -6.9570640 -6.348068
60 VARADOURO 4121 3720 2469 3.0312870 -33.6290323 -40.087357
61 BARRA DE GRAMAME 357 347 802 0.1178173 131.1239193 124.649860
62 COSTA DO SOL 609 8341 13470 1.0018109 61.4914279 2111.822660
63 GRAMAME 6288 24829 64884 8.0933123 161.3234524 931.870229
64 MUMBABA 463 7926 20050 8.6934791 152.9649256 4230.453564
66 NA NA NA NA NA NA NA
---
title: "NBA Scoring (2008)"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}
library(readxl)
library(dplyr)
library(ggplot2)
library(sf)
library(tmap)
library(stringr)
library(stringi)
library(geobr)


setwd('C:/CENSO/')
# População 2000
file_path_2000 <- "./input/base/Tabela 1522.xlsx"
populacao_2000 <- xlsx::read.xlsx(file_path_2000, sheetIndex  = 1, startRow = 2, encoding="UTF-8")
names(populacao_2000) <- c('bairros','pop_2000')
populacao_2000 <- subset(populacao_2000, !is.na(pop_2000))
populacao_2000$bairros <- gsub(' - João Pessoa \\(PB)','',populacao_2000$bairros)
populacao_2000$bairros <- gsub(' \\(PB)','',populacao_2000$bairros)
populacao_2000$bairros <- ifelse(populacao_2000$bairros == 'Muçumagro',
                                 'Mucumago',populacao_2000$bairros)
populacao_2000$bairros <- str_replace_all(str_to_upper(populacao_2000$bairros), "[- ]", "_")



# População 2010
file_path <- "./input/base/Censo 2010_dados gerais_bairros JP.xlsx"
populacao_2010 <- xlsx::read.xlsx(file_path, sheetIndex  = 2, startRow = 6, encoding="UTF-8")
populacao_2010 <- populacao_2010[,1:2]
names(populacao_2010) <- c('bairros','pop_2010')
populacao_2010 <- subset(populacao_2010, !is.na(pop_2010))
populacao_2010$bairros <- gsub(' - João Pessoa \\(PB)','',populacao_2010$bairros)
populacao_2010$bairros <- gsub(' \\(PB)','',populacao_2010$bairros)
populacao_2010$bairros <- str_replace_all(str_to_upper(populacao_2010$bairros), "[- ]", "_")

# População 2022
file_path <- "./input/base/Censo 2022_dados gerais_bairros JP.xlsx"
populacao_2022 <- xlsx::read.xlsx(file_path, sheetIndex  = 1, startRow = 5, encoding="UTF-8")
names(populacao_2022) <- c('bairros','pop_2022')
populacao_2022 <- subset(populacao_2022, !is.na(pop_2022))
populacao_2022$bairros <- stringr::str_trim(populacao_2022$bairros)
populacao_2022$bairros <- str_replace_all(str_to_upper(populacao_2022$bairros), "[- ]", "_")



# Shapefile
shapefile_path <- file.path("./input/shapefile/25SEE250GC_SIR.shp")
bairros <- st_read(shapefile_path, options = "ENCODING=WINDOWS-1252")

# Filtrar para João Pessoa e simplificar geometria
bairros_joao_pessoa <- bairros %>%
  filter(NM_MUNICIP == "JOÃO PESSOA")

bairros_simplificados <- bairros_joao_pessoa %>%
  group_by(bairros = NM_BAIRRO) %>%
  summarize(geometry = st_union(st_make_valid(geometry))) %>%
  ungroup() %>%
  mutate(bairros = str_replace_all(str_to_upper(bairros), "[- ]", "_"))

bairros_simplificados$area <- as.numeric(st_area(bairros_simplificados$geometry)/1000)


df_pop <- full_join(populacao_2000,populacao_2010) %>%
  full_join(populacao_2022) %>% 
  full_join(bairros_simplificados) %>% 
  mutate(densidade_2022  = pop_2022/area,
         cresc_2022_2010 = ((pop_2022 - pop_2010)/pop_2010)*100,
         cresc_2022_2000 = ((pop_2022 - pop_2000)/pop_2000)*100) %>% 
  st_as_sf()

# Filtrar e remover as geometrias vazias
df_pop <- df_pop[!st_is_empty(df_pop), ]

## Função para gerar os intervalos
generate_intervals <- function(var, n_intervals = 10, decimal_places = 2, cores = NULL) {
  # Calcular valores mínimos e máximos
  # min_val <- floor(min(var, na.rm = TRUE))
  # max_val <- ceiling(max(var, na.rm = TRUE))
  
  min_val <- min(var, na.rm = TRUE)
  max_val <- max(var, na.rm = TRUE)
  
  # Gerar os breaks separando valores negativos, zero e positivos
  if(min_val < 0 ){
      breaks <- unique(c(
    seq(min_val, 0, length.out = ceiling(n_intervals / 2) + 1), # Intervalos negativos até zero
    seq(0, max_val, length.out = floor(n_intervals / 2) + 1)    # Intervalos positivos a partir de zero
  ))

  } else {
      breaks <- unique(c(
  breaks <- seq(min_val, max_val, length.out = n_intervals + 1)
  ))

  }
  
  # Criar os labels
  labels <- paste0(
    gsub("\\.", ",", round(head(breaks, -1), decimal_places)), 
    " à ", 
    gsub("\\.", ",", round(tail(breaks, -1), decimal_places))
  )
  
  if(is.null(cores)){
   cores <- NULL 
  } else {
    cores <- cores
  }

  
  # Retornar uma lista com breaks e labels
  list(breaks = breaks, labels = labels, cores = cores)
}

tmap_mode("view")
```


Column {.tabset}
-------------------------------------
   
### Crescimento populacional (2022-2010)

```{r}

intervals <- generate_intervals(df_pop$cresc_2022_2010, n_intervals = 10, cores = c("red","pink",  "white", "lightblue","blue"))

#cartograma de diferença populacional

tm_shape(df_pop) +
  tm_polygons("cresc_2022_2010", title = "Crescimento Populacional (2010-2022)",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = intervals$cores, 
              midpoint = 0,
              legend.format = list(digits = 0),
              textNA = "Faltantes") +
  tm_borders() +
  tm_layout(title = "Crescimento Populacional por Bairro de João Pessoa entre 2010 e 2022")

```

### Crescimento populacional (2022-2000)

```{r}
intervals <- generate_intervals(df_pop$cresc_2022_2000, n_intervals = 9, cores = c("red","pink",  "white", "lightblue","blue"))

#cartograma de diferença populacional
tm_shape(df_pop) +
  tm_polygons("cresc_2022_2000", title = "Crescimento Populacional (2000-2022)",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = intervals$cores, midpoint = 0,
              legend.format = list(digits = 0),
              textNA = "Faltante") +
  tm_borders() +
  tm_layout(title = "Crescimento Populacional por Bairro de João Pessoa entre 2010 e 2022")

```




### Densidade populacional (2022)

```{r}
intervals <- generate_intervals(df_pop$densidade_2022, n_intervals = 12)

# Criar o cartograma usando a nova tabela de dados
tm_shape(df_pop) +
  tm_polygons("densidade_2022", title = "Densidade Populacional por Bairro",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = "Blues",
              legend.format = list(digits = 0),
              textNA = "Faltantes") +
  tm_borders() +
  tm_layout(title = "Densidade Populacional por Bairro de João Pessoa - CENSO 2022")
```

### População (2000)

```{r}
# Configuração do tmap
intervals <- generate_intervals(df_pop$pop_2000, n_intervals = 10)

# Criar o cartograma
tm_shape(df_pop) +
  tm_polygons("pop_2000", title = "População por Bairro",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = "Blues",
              legend.format = list(digits = 0),
              textNA = "Faltante") +
  tm_borders() +
  tm_layout(title = "População por bairro de João Pessoa - CENSO 2000")
```

### População (2010)

```{r}
# Configuração do tmap
intervals <- generate_intervals(df_pop$pop_2010, n_intervals = 10)

# Criar o cartograma
tm_shape(df_pop) +
  tm_polygons("pop_2010", title = "População por Bairro",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = "Blues",
              legend.format = list(digits = 0),
              textNA = "Faltante") +
  tm_borders() +
  tm_layout(title = "População por bairro de João Pessoa - CENSO 2010")
```

### População (2022)

```{r}
#carregar cartograma!
intervals <- generate_intervals(df_pop$pop_2022, n_intervals = 10)

# Criar o cartograma usando a nova tabela de dados
tm_shape(df_pop) +
  tm_polygons("pop_2022", title = "População por Bairro",
              style = "fixed",
              breaks = intervals$breaks, 
              labels = intervals$labels,
              palette = "Blues",
              legend.format = list(digits = 0),
              textNA = "Faltantes") +
  tm_borders() +
  tm_layout(title = "População por bairro de João Pessoa - CENSO 2022")
```

Column 
-------------------------------------

### Tabela

```{r}
table <- df_pop %>% as.data.frame() %>% 
               select(-c(area,geometry)) %>% 
  mutate(bairros = gsub("_"," ",bairros))
names(table) <- c('Bairros','População 2000','População 2010','População 2022','Densidade 2022 (hab/km²)','Crescimento (2022-2010)','Crescimento (2010-2000)')


# Gerar tabela com rolagem horizontal
library(kableExtra)
table %>%
  kable(escape = FALSE, align = "c") %>%  # escape = FALSE permite HTML no título
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), 
                full_width = TRUE, 
                position = "center") %>% 
  scroll_box(width = "100%", height = "800px")
```